package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.AdhesiveDAO;
import com.yunfeng.aolin.entity.Adhesive;
import com.yunfeng.aolin.service.AdhesiveService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class AdhesiveServiceImpl implements AdhesiveService {

	@Autowired
	private AdhesiveDAO adhesiveDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.AdhesiveService#get(java.lang.Long)
	 */
	@Override
	public Adhesive get(Long id) {
		return adhesiveDAO.findOne(id);
	}

	/**
	 * @param adhesive
	 * @see com.yunfeng.aolin.service.AdhesiveService#saveOrUpdate(com.yunfeng.aolin.entity.Adhesive)
	 */
	@Override
	public void saveOrUpdate(Adhesive adhesive) {
		adhesiveDAO.save(adhesive);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.AdhesiveService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		adhesiveDAO.delete(id);
	}

	@Override
	public List<Adhesive> findAll() {
		// TODO Auto-generated method stub
		return adhesiveDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.AdhesiveService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<Adhesive> findAll(Page page) {
		org.springframework.data.domain.Page<Adhesive> springDataPage = adhesiveDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param liaohao
	 * @return
	 * @see com.yunfeng.aolin.service.AdhesiveService#findByLiaohao(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<Adhesive> findByLiaohao(Page page, String liaohao) {
		org.springframework.data.domain.Page<Adhesive> springDataPage = adhesiveDAO
				.findByLiaohaoContaining(liaohao,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.AdhesiveService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<Adhesive> findByExample(Specification<Adhesive> specification,
			Page page) {
		org.springframework.data.domain.Page<Adhesive> springDataPage = adhesiveDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
